package api

import (
	"lutai/src/bll"
	"lutai/src/logger"
	"lutai/src/model"
	"net/http"

	"github.com/teambition/gear"
)

// Packet API接口
type Geography struct {
	models    *model.All
	geographyBll *bll.Geography
}

// Init 初始化Geography
func (p *Geography) Init(b *bll.All) *Geography {
	p.models = b.Models
	p.geographyBll = b.Geography
	return p
}

// Query /geography
func (p *Geography) Query(ctx *gear.Context) (err error) {
	areaType := ctx.Query("AreaType")
	geographyCode := ctx.Query("GeographyCode")

	datas, err := p.geographyBll.Query(areaType, geographyCode)
	if err != nil {
		logger.Errorf("Query Error:%s", err.Error())
		return gear.ErrInternalServerError.WithMsg("没有数据")
	}

	return ctx.JSON(http.StatusOK, datas)
}
